﻿@model GaclibWebPage.Models.GettingStartPageModel

@{
    ViewBag.Title = "GacLib - Getting Started - Step 3";
}
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shCore.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushCpp.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushXml.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/SyntaxHighlighter/scripts/shBrushPlain.js")"></script>
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shCore.css")" />
<link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/SyntaxHighlighter/styles/shThemeRDark.css")" />
<tr>
    <td align="left" valign="top" colspan="6">
        <h1>Step 3. @Model.TutorialTitles[2]</h1>
        <p>
            The following code can be found in <strong>Libraries\GacUI\GacUIDemo\HelloWorldXml\HelloWorldXml.vcxproj</strong> if you <a href="@Url.Action("Download")">DOWNLOAD</a> the latest source code.
        </p>
        <p>
            Now, we are going to modify the previous program to be XML based. Follow the steps:
        </p>
        <h2>Create the "UI" folder and add these two files:</h2>
        <p><b>Codegen.bat</b>. This file uses the <b>GacGen.exe</b> to process the XML resource and generate C++ codes.</p>
        <div class="CppCode">
            <pre class="brush: text; gutter: false;">
..\..\..\Public\Source\GacGen.exe HelloWorld.xml
copy HelloWorld.xml ..\..\Resources\HelloWorld.xml
pause
            </pre>
        </div>
        <p><b>HelloWorld.xml</b>. This is the XML resource file. The "<b>GacGenConfig</b>" section is a configuration for <b>GacGen.exe</b> to generate correct <b>#include</b> and <b>namespaces</b>.</p>
        <div class="CppCode">
            <pre class="brush: xml; gutter: false;">
&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Resource&gt;
  &lt;Folder name="GacGenConfig"&gt;
    &lt;Text name="Include"&gt;..\..\..\Public\Source\GacUIReflection.h&lt;/Text&gt;
    &lt;Text name="Name"&gt;HelloWorld&lt;/Text&gt;
    &lt;Text name="Prefix"&gt;&lt;/Text&gt;
  &lt;/Folder&gt;
  &lt;Folder name="MainWindow"&gt;
    &lt;Instance name="MainWindowResource"&gt;
      &lt;Instance ref.Class="helloworld::MainWindow"&gt;
        &lt;Window Text="Hello, world!" ClientSize="x:640 y:480"&gt;
          &lt;Label Text="Welcome to GacUI Library!"&gt;
            &lt;att.Font&gt;fontFamily:{Segoe UI} size:40 antialias:true&lt;/att.Font&gt;
          &lt;/Label&gt;
        &lt;/Window&gt;
      &lt;/Instance&gt;
    &lt;/Instance&gt;
  &lt;/Folder&gt;
&lt;/Resource&gt;
            </pre>
        </div>
        <h2>Execute Codegen.bat</h2>
        <p>You will get the following files. Add them to your project:</p>
        <ul>
            <li><b>HelloWorld.h</b>: You should include this file to reference the GUI in other source files. <b>DO NOT MODIFY</b>.</li>
            <li><b>HelloWorldPartialClasses.h/cpp</b>: Framework code. <b>DO NOT MODIFY</b>.</li>
            <li><b>MainWindow.h/cpp</b>: If you have multiple windows, you will get multiple pairs of such files naming after the class names. You can modify these files as you want, except the code between the commented <b>#region</b>.</li>
        </ul>
        <h2>A new Main.cpp</h2>
        <p>
            Now you can modify the <b>Main.cpp</b> to use the generated <b>helloworld::MainWindow</b> class directly. You should be notified that, the <b>HelloWorld.xml</b> is needed at run-time, so if you don't want to carry it with your binary, you can embedded it as a resource, and you are responsible to read it out by yourself.
        </p>
        <div class="cpp">
            <pre class="brush: cpp; gutter: false;">
#include "UI\HelloWorld.h"
#include &lt;Windows.h&gt;

using namespace vl::reflection::description;

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
	return SetupWindowsDirect2DRenderer();
}

void GuiMain()
{
    List&lt;WString&gt; errors;
    auto resource = GuiResource::LoadFromXml(L"..\\Resources\\HelloWorld.xml", errors);
	GetInstanceLoaderManager()-&gt;SetResource(L"Resource", resource);
	helloworld::MainWindow window;
	window.ForceCalculateSizeImmediately();
	window.MoveToScreenCenter();
	GetApplication()-&gt;Run(&window);
}
            </pre>
        </div>
        <h1>See also ...</h1>
        <ul>
            @for (int index = 0; index < Model.TutorialTitles.Length; index++)
            {
                <li>Step @(index + 1). <a href="@Url.Action("GettingStart_" + (index + 1).ToString(), "Home")">@Model.TutorialTitles[index]</a></li>
            }
        </ul>
    </td>
</tr>
<script type="text/javascript">
    SyntaxHighlighter.all()
</script>